﻿Imports System.Drawing.Drawing2D

Class ToolbarRenderer
    Inherits ToolStripProfessionalRenderer

    Sub New()
        RoundedEdges = False
    End Sub

    Protected Overrides Sub OnRenderToolStripBorder(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
        MyBase.OnRenderToolStripBorder(e)
        Dim R As Rectangle = e.AffectedBounds
        e.Graphics.DrawLine(New Pen(LineColor), R.Left, R.Bottom - 1, R.Right, R.Bottom - 1)
    End Sub

    Protected Overrides Sub OnRenderToolStripBackground(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
        Dim R As New Rectangle(0, 0, e.ToolStrip.Width, e.ToolStrip.Height)
        'MyBase.OnRenderToolStripBackground(e)
        If e.ConnectedArea.Height = 0 Then
            e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(216, 224, 255)), R)
            R.Height \= 2
            e.Graphics.FillRectangle(LGBv(R, Color.FromArgb(192, Color.White), Color.FromArgb(64, Color.White)), R)
        End If
    End Sub

    Protected Overrides Sub OnRenderArrow(ByVal e As System.Windows.Forms.ToolStripArrowRenderEventArgs)
        e.ArrowColor = Color.FromArgb(32, 48, 80)
        e.ArrowRectangle.Inflate(1, 1)
        MyBase.OnRenderArrow(e)
    End Sub

    Protected Overrides Sub OnRenderItemText(ByVal e As System.Windows.Forms.ToolStripItemTextRenderEventArgs)
        If TypeOf e.Item Is ToolStripDropDownButton Or TypeOf e.Item Is ToolStripButton Then e.TextColor = Color.FromArgb(32, 48, 80)
        MyBase.OnRenderItemText(e)
    End Sub

    Protected Overrides Sub OnRenderDropDownButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
        e.Graphics.SmoothingMode = SmoothingMode.HighQuality
        Dim R As New Rectangle(0, 0, e.Item.Width - 1, e.Item.Height - 1)
        If e.Item.Pressed Then
            DrawRoundRect(e.Graphics, R, New Pen(Color.FromArgb(96, Color.Black)), 4)
            FillRoundRect(e.Graphics, R, New SolidBrush(Color.FromArgb(32, Color.Black)), 4)
        ElseIf e.Item.Selected Then
            Dim RR As Rectangle = R
            e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality
            e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(216, 224, 255)), RR)
            RR.Height \= 2
            e.Graphics.FillRectangle(LGBv(RR, Color.FromArgb(192, Color.White), Color.FromArgb(64, Color.White)), RR)
            RR.Offset(0, RR.Height)
            RR.Height += 1
            e.Graphics.FillRectangle(LGBv(RR, Color.FromArgb(0, Color.White), Color.FromArgb(64, Color.Black)), RR)
            e.Graphics.PixelOffsetMode = PixelOffsetMode.None
            DrawRoundRect(e.Graphics, R, New Pen(Color.FromArgb(64, Color.Black)), 4)
            R.Inflate(-1, -1)
            DrawRoundRect(e.Graphics, R, New Pen(Color.FromArgb(128, Color.White)), 3)
        End If
        e.Graphics.SmoothingMode = SmoothingMode.None
    End Sub

    Protected Overrides Sub OnRenderButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
        OnRenderDropDownButtonBackground(e)
    End Sub

End Class
